package com.sdy.hospitalguard.biz.event;

import com.sdy.common.utils.Assert;
import com.sdy.hospitalguard.biz.constants.MqConstants;
import com.sdy.mq.service.MqProducerService;
import com.sdy.mvc.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 事件发布者
 * @author zhouziqiang
 */
@Service
@Slf4j
public class EventPublisher {
    @Autowired
    private MqProducerService mqProducerService;
    
    public void publishWebsocketEvent(WebsocketEvent event) throws Exception {
        Assert.isNull(event.getUserId(), "参数userId不能为空");
        Assert.isBlank(event.getEventType(), "参数eventType不能为空");
        Assert.isNull(event.getData(), "参数data不能为空");
        log.info("发布事件ID={}, TYPE={}, USER_ID={}", event.getEventId(), event.getEventType(), event.getUserId());
        mqProducerService.send(MqConstants.Tags.TAG_WS_EVENT, JsonUtil.serialize(event));
    }
}
